package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.api.bean.AssetsRecode
import client.comm.baoding.api.bean.AssetsRecode2
import client.comm.baoding.api.bean.GoodsDetailTrade
import client.comm.baoding.api.bean.Zcjl
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret


class ZcjlViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val isTwoLoading = MutableLiveData<Boolean>(false)
    val isThreeLoading = MutableLiveData<Boolean>(false)
    val isFourLoading = MutableLiveData<Boolean>(false)
    val isFiveLoading = MutableLiveData<Boolean>(false)

    val isjljlLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val pageTwo = MutableLiveData<Int>(0)
    val pageThree = MutableLiveData<Int>(0)
    val pageFour = MutableLiveData<Int>(0)
    val pageFive = MutableLiveData<Int>(0)

    val pagejljl = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<Zcjl>>()
    val callTwo = MutableLiveData<JsonResult<Zcjl>>()
    val callThree = MutableLiveData<JsonResult<Zcjl>>()
    val callFour = MutableLiveData<JsonResult<Zcjl>>()
    val callFive = MutableLiveData<JsonResult<Zcjl>>()
    val calljljl = MutableLiveData<JsonResult<Zcjl>>()
    val callStoreIncome = MutableLiveData<JsonResult<Zcjl>>()

    val callAssets = MutableLiveData<JsonResult<AssetsRecode>>()
    val callAssets2 = MutableLiveData<JsonResult<AssetsRecode2>>()

    val refundRet = MutableLiveData<JsonResult<Ret>>()

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.zcjl(pageOne.value!!, 1)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwo() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.zcjl(pageTwo.value!!, 9)
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwo.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }

    fun holdThree() {
        if (isThreeLoading.value!!)
            return
        hold({
            server.zcjl(pageThree.value!!, 2)
        }, {
            isThreeLoading.value = true
            pageThree.value = pageThree.value!! + 1
        }, {
            callThree.value = it
        }, complete = {
            isThreeLoading.value = false
        })
    }

    fun holdFour() {
        if (isFourLoading.value!!)
            return
        hold({
            server.zcjl(pageFour.value!!, 16)
        }, {
            isFourLoading.value = true
            pageFour.value = pageFour.value!! + 1
        }, {
            callFour.value = it
        }, complete = {
            isFourLoading.value = false
        })
    }

    fun holdFive() {
        if (isFiveLoading.value!!)
            return
        hold({
            server.zcjl(pageFive.value!!, 5)
        }, {
            isFiveLoading.value = true
            pageFive.value = pageFive.value!! + 1
        }, {
            callFive.value = it
        }, complete = {
            isFiveLoading.value = false
        })
    }

    fun holdjljl() {
        if (isjljlLoading.value!!)
            return
        hold({
            server.zcjl(pagejljl.value!!, 10)
        }, {
            isjljlLoading.value = true
            pagejljl.value = pagejljl.value!! + 1
        }, {
            calljljl.value = it
        }, complete = {
            isjljlLoading.value = false
        })
    }

    /*fun holdAssets() {
        if (isOneLoading.value!!)
            return
        hold({
            server.trade_my_assets(pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callAssets.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }*/

    fun myTradeList() {
        if (isOneLoading.value!!)
            return
        hold({
            server.my_trade_list()
        }, {
            isOneLoading.value = true
        }, {
            callAssets2.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdStoreIncome() {
        if (isOneLoading.value!!)
            return
        hold({
            server.zcjl(pageOne.value!!, 6)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callStoreIncome.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }


    fun holdOneDsf() {
        if (isOneLoading.value!!)
            return
        hold({
            server.zcjl(pageOne.value!!, 21)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwoKjy() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.zcjl(pageTwo.value!!, 22)
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwo.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }

    fun holdThreeTjq() {
        if (isThreeLoading.value!!)
            return
        hold({
            server.zcjl(pageThree.value!!, 23)
        }, {
            isThreeLoading.value = true
            pageThree.value = pageThree.value!! + 1
        }, {
            callThree.value = it
        }, complete = {
            isThreeLoading.value = false
        })
    }


    fun holdTuiKuan(detail: AssetsRecode2.MyGoodsInfo, num: String) {
        hold({
            server.trade_refund_tj(
                "${detail.goods_id}",
                num
            )
        }, {
            isShowing.value = true
        }, success = {
            refundRet.value = it
        }, complete = {
            isShowing.value = false
        })
    }


}